package com.zhan.rkforum.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author wujiazhan
 * @className KaptchaConfig
 * @description 验证码工具包配置类
 * @date 2021-06-11 10:49
 */
@SuppressWarnings("all")
@Configuration
public class KaptchaConfig {


    @Bean
    public Producer kaptchaProducer(){
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width","100");//设置图片的宽度
        properties.setProperty("kaptcha.image.height","40");//设置图片的长度
        properties.setProperty("kaptcha.textproducer.font.size","32");//设置字体大小
        properties.setProperty("kaptcha.textproducer.font.color","0,0,0");//设置字体色号
        properties.setProperty("kaptcha.textproducer.char.String","0123456789QWERTYUIOPASDFGHJKLZXCVBNM");//设置文字范围
        properties.setProperty("kaptcha.textproducer.char.length","4");//设置字符长度
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");//设置干扰实现类

        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }

}
